home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / hwclock.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-09-25  |  5KB  |  152 lines

  1. #!/bin/sh
  2. # hwclock.sh    Set and adjust the CMOS clock, according to the UTC
  3. #        setting in /etc/default/rcS (see also rcS(5)).
  4. #
  5. # Version:    @(#)hwclock.sh  2.00  14-Dec-1998  miquels@cistron.nl
  6. #
  7. # Patches:
  8. #        2000-01-30 Henrique M. Holschuh <hmh@rcm.org.br>
  9. #         - Minor cosmetic changes in an attempt to help new
  10. #           users notice something IS changing their clocks
  11. #           during startup/shutdown.
  12. #         - Added comments to alert users of hwclock issues
  13. #           and discourage tampering without proper doc reading.
  14.  
  15. # WARNING:    Please read /usr/share/doc/util-linux/README.Debian.hwclock
  16. #        before changing this file. You risk serious clock
  17. #        misbehaviour otherwise.
  18.  
  19. ### BEGIN INIT INFO
  20. # Provides:          hwclock
  21. # Required-Start:    mountdevsubfs
  22. # Required-Stop:     $local_fs
  23. # Default-Start:     S
  24. # Default-Stop:      0 6
  25. ### END INIT INFO
  26.  
  27. FIRST=no    # debian/rules sets this to 'yes' when creating hwclockfirst.sh
  28.  
  29. # Set this to any options you might need to give to hwclock, such
  30. # as machine hardware clock type for Alphas.
  31. HWCLOCKPARS=
  32.  
  33. hwclocksh()
  34. {
  35.     [ ! -x /sbin/hwclock ] && return 0
  36.     . /etc/default/rcS
  37.  
  38.     . /lib/lsb/init-functions
  39.     verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  40.  
  41.     [ "$GMT" = "-u" ] && UTC="yes"
  42.     case "$UTC" in
  43.        no|"")    GMT="--localtime"
  44.         UTC=""
  45.         if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then
  46.             if [ -z "$TZ" ]; then
  47.             log_action_msg "System clock was not updated at this time"
  48.             return 1
  49.             fi
  50.         fi
  51.         ;;
  52.        yes)    GMT="--utc"
  53.         UTC="--utc"
  54.         ;;
  55.        *)    log_action_msg "Unknown UTC setting: \"$UTC\""; return 1 ;;
  56.     esac
  57.  
  58.     case "$BADYEAR" in
  59.        no|"")    BADYEAR="" ;;
  60.        yes)    BADYEAR="--badyear" ;;
  61.        *)    log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;;
  62.     esac
  63.  
  64.     case "$1" in
  65.     start)
  66.         if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
  67.         echo "0.0 0 0.0" > /etc/adjtime
  68.         fi
  69.  
  70.         if [ ! -w /etc/adjtime ]; then
  71.         NOADJ="--noadjfile"
  72.         else
  73.             NOADJ=""
  74.         fi
  75.  
  76.         if [ "$FIRST" != yes ]; then
  77.         # Uncomment the hwclock --adjust line below if you want
  78.         # hwclock to try to correct systematic drift errors in the
  79.         # Hardware Clock.
  80.         #
  81.         # WARNING: If you uncomment this option, you must either make
  82.         # sure *nothing* changes the Hardware Clock other than
  83.         # hwclock --systohc, or you must delete /etc/adjtime
  84.         # every time someone else modifies the Hardware Clock.
  85.         #
  86.         # Common "vilains" are: ntp, MS Windows, the BIOS Setup
  87.         # program.
  88.         #
  89.         # WARNING: You must remember to invalidate (delete)
  90.         # /etc/adjtime if you ever need to set the system clock
  91.         # to a very different value and hwclock --adjust is being
  92.         # used.
  93.         #
  94.         # Please read /usr/share/doc/util-linux/README.Debian.hwclock
  95.         # before enabling hwclock --adjust.
  96.  
  97.         #/sbin/hwclock --adjust $GMT $BADYEAR
  98.         :
  99.         fi
  100.  
  101.         if [ "$HWCLOCKACCESS" != no ]; then
  102.         log_action_msg "Setting the system clock"
  103.  
  104.         # Copies Hardware Clock time to System Clock using the correct
  105.         # timezone for hardware clocks in local time, and sets kernel
  106.         # timezone. DO NOT REMOVE.
  107.         if /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
  108.             #    Announce the local time.
  109.             verbose_log_action_msg "System Clock set to: `date $UTC`"
  110.         else
  111.             log_warning_msg "Unable to set System Clock to: `date $UTC`"
  112.         fi
  113.         else
  114.         verbose_log_action_msg "Not setting System Clock"
  115.         fi
  116.         ;;
  117.     stop|restart|reload|force-reload)
  118.         #
  119.         # Updates the Hardware Clock with the System Clock time.
  120.         # This will *override* any changes made to the Hardware Clock.
  121.         #
  122.         # WARNING: If you disable this, any changes to the system
  123.         #          clock will not be carried across reboots.
  124.         #
  125.         if [ "$HWCLOCKACCESS" != no ]; then
  126.         log_action_msg "Saving the system clock"
  127.         if [ "$GMT" = "-u" ]; then
  128.             GMT="--utc"
  129.         fi
  130.         if /sbin/hwclock --systohc $GMT $HWCLOCKPARS $BADYEAR; then
  131.             verbose_log_action_msg "Hardware Clock updated to `date`"
  132.         fi
  133.         else
  134.         verbose_log_action_msg "Not saving System Clock"
  135.         fi
  136.         ;;
  137.     show)
  138.         if [ "$HWCLOCKACCESS" != no ]; then
  139.         /sbin/hwclock --show $GMT $HWCLOCKPARS $BADYEAR
  140.         fi
  141.         ;;
  142.     *)
  143.         log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}"
  144.         log_success_msg "       start sets kernel (system) clock from hardware (RTC) clock"
  145.         log_success_msg "       stop and reload set hardware (RTC) clock from kernel (system) clock"
  146.         return 1
  147.         ;;
  148.     esac
  149. }
  150.  
  151. hwclocksh "$@"
  152.